package org.nabc.core;

public abstract class AbstractStringOperation {
    protected String getTableName(String tableName, String... tablePrefix) {
        for (String str : tablePrefix) {
            if (tableName.indexOf(str) == 0) {
                return capitalLetter(tableName.substring(str.length()));
            }
        }
        return capitalLetter(tableName);
    }

    protected String conversionHump(String columnName) {
        String[] strings = columnName.split("_");
        StringBuffer stringBuffer = new StringBuffer();

        stringBuffer.append(strings[0]);

        for (int i = 1; i < strings.length; i++) {
            stringBuffer.append(capitalLetter(strings[i]));
        }

        return stringBuffer.toString();
    }

    protected String capitalLetter(String str) {
        return Character.toUpperCase(str.charAt(0)) + str.substring(1);
    }

    protected String lowerLetter(String str) {
        return Character.toLowerCase(str.charAt(0)) + str.substring(1);
    }

    protected String mapperSqlTypeToType(String str, String type) {
        if (str.equals("int") || str.equals("tinyint")) {
            return "int";
        } else if (str.equals("bigint")) {
            if (type.equals("go")) {
                return "int64";
            }

            return "long";
        } else if (str.equals("varchar") || str.equals("text")) {
            if (type.equals("go")) {
                return "string";
            }

            return "String";
        } else if (str.equals("datetime") || str.equals("timestamp")) {
            return "LocalDateTime";
        } else if (str.equals("date")) {
            return "Date";
        } else if (str.equals("decimal")) {
            return "double";
        }

        return "未知";
    }
}
